using System.Reflection;
using System.Windows.Media;

//namespace ibba.src.sl.recursos //.Helpers 
//{
    public class GeneralHelper
    {
        /// <summary>
        /// Sincroniza os valores entre dois objetos
        /// </summary>
        /// <param name="origem">objeto de com valores</param>
        /// <param name="destino">objeto que recebera os valores</param>
        /// <returns>objeto destino</returns>
        public static T SincProperties<T>(object origem, T destino)
        {
            foreach (PropertyInfo po in origem.GetType().GetProperties())
            {
                foreach (PropertyInfo pd in destino.GetType().GetProperties())
                {
                    if (pd.CanWrite && po.CanRead)
                        if (pd.Name.Equals(po.Name))
                        {
                            pd.SetValue(destino, po.GetValue(origem, null), null);
                            break;
                        }
                }
            }

            return destino;
        }

        public static T Clone<T>(T entity)
        {
            T value = System.Activator.CreateInstance<T>();

            foreach (PropertyInfo p in entity.GetType().GetProperties())
            {
                p.SetValue(value, p.GetValue(entity, null), null);
            }

            return value;
        }

        public static Color StringToColor(string pHexColor)
        {               
            return Color.FromArgb(byte.Parse(pHexColor.Substring(0, 2)),
                                  byte.Parse(pHexColor.Substring(2, 2)),
                                  byte.Parse(pHexColor.Substring(4, 2)),
                                  byte.Parse(pHexColor.Substring(6, 2)));
        }

        public static string FormatDecimal(string pValor, short pNumDigDecimal)
        {
            decimal d;
            decimal.TryParse(pValor, out d);

            return d.ToString(string.Format("n{0}", pNumDigDecimal));
        }        
    }
//}
